package com.huli.controller;

import com.github.pagehelper.PageInfo;
import com.huli.pojo.OrderInfo;
import com.huli.service.OrderInfoService;
import com.huli.util.Result;
import com.huli.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import java.util.List;

@RestController
@RequestMapping("/orderInfo")
public class OrderInfoController {
    @Autowired
    private OrderInfoService orderInfoService;

    // 订单列表
    @RequestMapping("/orderInfoList")
    public Result orderInfoList(OrganizationUserVo param){

        try {
            // 调用orderInfoService的orderInfoList方法，传入OrganizationUserVo参数
            OrganizationUserVo orderList = orderInfoService.orderInfoList(param);
            // 返回查询结果
            return Result.success(orderList);
        } catch (Exception e) {
            // 打印异常信息
            e.printStackTrace();
            // 返回查询失败信息
            return Result.error("查询失败");
        }
    }

    // 修改订单
    @RequestMapping("/updateOrderInfo")
    public Result updateOrderInfo(OrderInfo orderInfo){
        try {
            // 调用orderInfoService的updateOrderInfo方法，传入OrderInfo参数
            orderInfoService.updateOrderInfo(orderInfo);
            // 返回修改成功的消息
            return Result.success("修改成功");
        } catch (Exception e) {
            // 打印异常信息
            e.printStackTrace();
            // 返回修改失败的消息
            return Result.error("修改失败");
        }
    }
    // 回显订单详情
    @RequestMapping("/orderInfoById")
    public Result orderInfoById(Long id){
        try {
            // 根据id查询订单详情
            OrderInfo orderList = orderInfoService.orderInfoById(id);
            // 返回查询结果
            return Result.success(orderList);
        } catch (Exception e) {
            // 打印异常信息
            e.printStackTrace();
            // 返回查询失败信息
            return Result.error("查询失败");
        }
    }

    // 订单状态
    @RequestMapping("/orderStatus")
    public Result orderStatus(Integer status){
        try {
            // 调用orderInfoService的orderStatus方法，传入订单状态
            orderInfoService.orderStatus(status);
            // 返回修改成功的消息
            return Result.success("修改成功");
        } catch (Exception e) {
            // 打印异常信息
            e.printStackTrace();
            // 返回修改失败的消息
            return Result.error("修改失败");
        }
    }

    // 派单
    @RequestMapping("/orderInfoUser")
    public Result orderInfoUser(Long id,Long userId){
        try {
            // 调用orderInfoService的orderInfoUser方法，传入id和userId
            orderInfoService.orderInfoUser(id,userId);
            // 返回派单成功的消息
            return Result.success("派单成功");
        } catch (Exception e) {
            // 打印异常信息
            e.printStackTrace();
            // 返回派单失败的消息
            return Result.error("派单失败");
        }
    }

    // 订单以完成状态查询
    @RequestMapping("/orderInfoStatusList3")
    public Result orderInfoStatusList(OrganizationUserVo param){
        try {
            OrganizationUserVo orderList = orderInfoService.orderInfoStatusList(param);
            return Result.success(orderList);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("查询失败");
        }
    }
    // 订单待派单状态查询
    @RequestMapping("/orderInfoStatusList0")
    public Result orderInfoStatusList0(OrganizationUserVo param){
        try {
            OrganizationUserVo orderList = orderInfoService.orderInfoStatusList0(param);
            return Result.success(orderList);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("查询失败");
        }
    }
    @RequestMapping("/orderInfoList2")
    public Result orderInfoList2(OrderDetailVO orderInfo) {
        try {
            // 设置分页参数
//            orderInfo.setPageNum(pageNum);
//            orderInfo.setPageSize(pageSize);
            // 使用 PageInfo 包装结果
            PageInfo<OrderDetailVO> orderInfos = orderInfoService.orderInfoList2(orderInfo);
            return Result.success(orderInfos);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("查询失败");
        }
    }
    @RequestMapping("/orderInfoList55")
    public Result orderInfoList55( OrderInfoVo orderInfo){
        try
            {
//                orderInfo.setPageNum(pageNum);
//                orderInfo.setPageSize(pageSize);
                PageInfo<OrderInfoVo> orderInfos = orderInfoService.orderInfoList55(orderInfo);
                return Result.success(orderInfos);
            } catch (Exception e)
            {
                e.printStackTrace();
                return Result.error("查询失败");
            }
    }
    @RequestMapping("/orderInfoList66")
    public Result orderInfoList66( OrderInfooVo orderInfo){
        try
            {
//                orderInfo.setPageNum(pageNum);
//                orderInfo.setPageSize(pageSize);
                PageInfo<OrderInfooVo> orderInfos = orderInfoService.orderInfoList66(orderInfo);
                return Result.success(orderInfos);
            } catch (Exception e)
            {
                e.printStackTrace();
                return Result.error("查询失败");
            }
    }
    @RequestMapping("/orderInfoList77")
    public Result orderInfoList77(LogInfoVO orderInfo) {
        try {
            PageInfo<LogInfoVO> orderInfos = orderInfoService.orderInfoList77(orderInfo);
            return Result.success(orderInfos);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("查询失败");
        }
    }
    @RequestMapping("/orderInfoList88")
    public Result orderInfoList88( ServiceInfoVO serviceInfo){
        try
            {
//                serviceInfo.setPageNum(pageNum);
//                serviceInfo.setPageSize(pageSize);
                PageInfo<ServiceInfoVO> orderInfos = orderInfoService.orderInfoList88(serviceInfo);
                return Result.success(orderInfos);
            } catch (Exception e)
            {
                e.printStackTrace();
                return Result.error("查询失败");
            }
    }
    @RequestMapping("/findAllOrderInfo")
    public Result findAllOrderInfo(){
        try {
            List<OrderInfo> orderInfos = orderInfoService.findAllOrderInfo();
            return Result.success(orderInfos);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("查询失败");
        }
    }
}